Source: U.S. Census Bureau, ACS 5-year, Table B27015 and B01003 Table 1 title: HEALTH INSURANCE COVERAGE STATUS AND TYPE BY HOUSEHOLD INCOME IN THE PAST 12 MONTHS, https://data.census.gov/cedsci/table?q=B27015
Table 2 title: TOTAL POPULATION, https://data.census.gov/cedsci/table?q=b01003
# Reference: https://walkerke.github.io/tidycensus/articles/basic-usage.html
# Reference: https://juliasilge.com/blog/using-tidycensus/
# View Census data tables available
#View(load_variables(2017, "acs5", cache = TRUE))
# persons on public health insurance from census in Texas counties
public.HI <- get_acs(geography = "county",
variables = c("B27015_002"),
state = "TX",
geometry = FALSE,
year = 2017)
## Getting data from the 2013-2017 5-year ACS
# population of Texas counties
pop <- get_acs(geography = "county",
variables = c("B01003_001"),
state = "TX",
geometry = FALSE,
year = 2017)
## Getting data from the 2013-2017 5-year ACS
public.HI.pop <- inner_join(public.HI, pop, by = c("GEOID" = "GEOID", "NAME" = "NAME"))
# get percentage of population of county on public health insurance
public.HI.pop %<>%
mutate(perc_HI = round(estimate.x / estimate.y, digits = 2))
# get tigris data on counties in Texas and merge with health insurance data frame
# Reference: https://github.com/walkerke/tigris
tx.counties <- counties(state = 48)
##
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|==== | 7%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|====== | 10%
|
|======= | 10%
|
|======= | 11%
|
|======= | 12%
|
|======== | 12%
|
|======== | 13%
|
|========= | 13%
|
|========= | 14%
|
|========= | 15%
|
|========== | 15%
|
|========== | 16%
|
|=========== | 16%
|
|=========== | 17%
|
|=========== | 18%
|
|============ | 18%
|
|============ | 19%
|
|============= | 19%
|
|============= | 20%
|
|============= | 21%
|
|============== | 21%
|
|============== | 22%
|
|=============== | 22%
|
|=============== | 23%
|
|=============== | 24%
|
|================ | 24%
|
|================ | 25%
|
|================= | 25%
|
|================= | 26%
|
|================= | 27%
|
|================== | 27%
|
|================== | 28%
|
|=================== | 28%
|
|=================== | 29%
|
|=================== | 30%
|
|==================== | 30%
|
|==================== | 31%
|
|==================== | 32%
|
|===================== | 32%
|
|===================== | 33%
|
|====================== | 33%
|
|====================== | 34%
|
|====================== | 35%
|
|======================= | 35%
|
|======================= | 36%
|
|======================== | 36%
|
|======================== | 37%
|
|======================== | 38%
|
|========================= | 38%
|
|========================= | 39%
|
|========================== | 39%
|
|========================== | 40%
|
|========================== | 41%
|
|=========================== | 41%
|
|=========================== | 42%
|
|============================ | 42%
|
|============================ | 43%
|
|============================ | 44%
|
|============================= | 44%
|
|============================= | 45%
|
|============================== | 45%
|
|============================== | 46%
|
|============================== | 47%
|
|=============================== | 47%
|
|=============================== | 48%
|
|================================ | 48%
|
|================================ | 49%
|
|================================ | 50%
|
|================================= | 50%
|
|================================= | 51%
|
|================================= | 52%
|
|================================== | 52%
|
|================================== | 53%
|
|=================================== | 53%
|
|=================================== | 54%
|
|=================================== | 55%
|
|==================================== | 55%
|
|==================================== | 56%
|
|===================================== | 56%
|
|===================================== | 57%
|
|===================================== | 58%
|
|====================================== | 58%
|
|====================================== | 59%
|
|======================================= | 59%
|
|======================================= | 60%
|
|======================================= | 61%
|
|======================================== | 61%
|
|======================================== | 62%
|
|========================================= | 62%
|
|========================================= | 63%
|
|========================================= | 64%
|
|========================================== | 64%
|
|========================================== | 65%
|
|=========================================== | 65%
|
|=========================================== | 66%
|
|=========================================== | 67%
|
|============================================ | 67%
|
|============================================ | 68%
|
|============================================= | 68%
|
|============================================= | 69%
|
|============================================= | 70%
|
|============================================== | 70%
|
|============================================== | 71%
|
|============================================== | 72%
|
|=============================================== | 72%
|
|=============================================== | 73%
|
|================================================ | 73%
|
|================================================ | 74%
|
|================================================ | 75%
|
|================================================= | 75%
|
|================================================= | 76%
|
|================================================== | 76%
|
|================================================== | 77%
|
|================================================== | 78%
|
|=================================================== | 78%
|
|=================================================== | 79%
|
|==================================================== | 79%
|
|==================================================== | 80%
|
|==================================================== | 81%
|
|===================================================== | 81%
|
|===================================================== | 82%
|
|====================================================== | 82%
|
|====================================================== | 83%
|
|====================================================== | 84%
|
|======================================================= | 84%
|
|======================================================= | 85%
|
|======================================================== | 85%
|
|======================================================== | 86%
|
|======================================================== | 87%
|
|========================================================= | 87%
|
|========================================================= | 88%
|
|========================================================== | 88%
|
|========================================================== | 89%
|
|========================================================== | 90%
|
|=========================================================== | 90%
|
|=========================================================== | 91%
|
|=========================================================== | 92%
|
|============================================================ | 92%
|
|============================================================ | 93%
|
|============================================================= | 93%
|
|============================================================= | 94%
|
|============================================================= | 95%
|
|============================================================== | 95%
|
|============================================================== | 96%
|
|=============================================================== | 96%
|
|=============================================================== | 97%
|
|=============================================================== | 98%
|
|================================================================ | 98%
|
|================================================================ | 99%
|
|=================================================================| 99%
|
|=================================================================| 100%
tx.counties@data <- merge(tx.counties@data, public.HI.pop, sort = FALSE, by = "GEOID")
# create palettes of colors
# Reference: https://rstudio.github.io/leaflet/colors.html
pal <- colorBin(palette = "Oranges",
bins = c(0, .05, 0.1, 0.15, 0.2, 0.25, .3, .35, .4),
domain = tx.counties$perc_HI)
pal2 <- colorBin(palette = "PuRd",
bins = c(0, .05, 0.1, 0.15, 0.2, 0.25, .3, .35, .4),
domain = tx.counties$perc_HI)
leaflet(tx.counties) %>%
addProviderTiles("OpenStreetMap") %>%
# Orange shading of public health insurance
addPolygons(fillColor = ~pal(perc_HI),
weight = 1,
opacity = 1,
color = "black",
fillOpacity = 0.6,
popup = ~paste0("<b>", NAMELSAD, "</b> ",
"<br>Residents: ", format(estimate.y, big.mark = "," ),
"<br>Residents on public health insurance: ", format(estimate.x,big.mark = ","),
"<br>Percent of residents on public<br>health insurance: ",
perc_HI * 100, "%"),
group = "Orange") %>%
# Purple shading of public health insurance
addPolygons(fillColor = ~pal2(perc_HI),
weight = 1,
opacity = 1,
color = "black",
fillOpacity = 0.6,
popup = ~paste0("<b>", NAMELSAD, "</b> ",
"<br>Residents: ", format(estimate.y, big.mark = "," ),
"<br>Residents on public health insurance: ", format(estimate.x,big.mark = ","),
"<br>Percent of residents on public<br>health insurance: ",
perc_HI * 100, "%"),
group = "Purple") %>%
# Reference: https://rstudio.github.io/leaflet/legends.html
# Reference: https://stackoverflow.com/questions/38701359/grouped-layer-control-in-leaflet-r
# Reference: https://rstudio.github.io/leaflet/showhide.html
addLegend(position = "bottomright",
pal = pal,
values = ~perc_HI,
title = "Percent of county residents<br>on public health insurance",
labFormat = labelFormat(digits = 0, transform = function(x) 100 * x, suffix = "%" ),
group = "Orange") %>%
addLegend(position = "bottomright",
pal = pal2,
values = ~perc_HI,
title = "Percent of county residents<br>on public health insurance",
labFormat = labelFormat(digits = 0, transform = function(x) 100 * x, suffix = "%" ),
group = "Purple") %>%
# allow user to change color of shading and legend
addLayersControl(overlayGroups = c("Orange", "Purple"),
options = layersControlOptions(collapsed=FALSE)) %>%
# by default, hide the group "Purple"
hideGroup("Purple")